#ifndef __oled_H
#define __oled_H 

#include "main.h"

//---------------###用户配置选项--------------
#define oled_INTERFACE 2    //###协议选择 /1:SPI,/2:I2C,/3:模拟SPI,/4:模拟I2C

#if oled_INTERFACE == 1 
    #include "spi.h"
    #define oled_spi hspi2           //###选择spi
    #define oled_RES_Pin GPIO_PIN_15 //###修改GPIO
    #define oled_RES_GPIO_Port GPIOC
    #define oled_DC_Pin GPIO_PIN_0
    #define oled_DC_GPIO_Port GPIOC
    #define oled_RES_Clr()  HAL_GPIO_WritePin(oled_RES_GPIO_Port,oled_RES_Pin, GPIO_PIN_RESET)
    #define oled_RES_Set()  HAL_GPIO_WritePin(oled_RES_GPIO_Port,oled_RES_Pin, GPIO_PIN_SET)
    #define oled_DC_Clr()   HAL_GPIO_WritePin(oled_DC_GPIO_Port,oled_DC_Pin, GPIO_PIN_RESET)
    #define oled_DC_Set()   HAL_GPIO_WritePin(oled_DC_GPIO_Port,oled_DC_Pin, GPIO_PIN_SET)

    
#elif  oled_INTERFACE == 2
    #include "i2c.h"
    #define oled_i2c hi2c1          //###选择i2c
    #define oled_I2C_ADDR 0x78      // I2C设备地址
         
#elif  oled_INTERFACE == 3
    #define oled_SCL_Pin GPIO_PIN_13 //###修改GPIO
    #define oled_SCL_GPIO_Port GPIOC
    #define oled_SDA_Pin GPIO_PIN_14
    #define oled_SDA_GPIO_Port GPIOC
    #define oled_RES_Pin GPIO_PIN_15
    #define oled_RES_GPIO_Port GPIOC
    #define oled_DC_Pin GPIO_PIN_0
    #define oled_DC_GPIO_Port GPIOC
     
    #define oled_SCL_Clr()  HAL_GPIO_WritePin(oled_SCL_GPIO_Port,oled_SCL_Pin, GPIO_PIN_RESET)
    #define oled_SCL_Set()  HAL_GPIO_WritePin(oled_SCL_GPIO_Port,oled_SCL_Pin, GPIO_PIN_SET)
    #define oled_SDA_Clr()  HAL_GPIO_WritePin(oled_SDA_GPIO_Port,oled_SDA_Pin, GPIO_PIN_RESET)
    #define oled_SDA_Set()  HAL_GPIO_WritePin(oled_SDA_GPIO_Port,oled_SDA_Pin, GPIO_PIN_SET)
    #define oled_RES_Clr()  HAL_GPIO_WritePin(oled_RES_GPIO_Port,oled_RES_Pin, GPIO_PIN_RESET)
    #define oled_RES_Set()  HAL_GPIO_WritePin(oled_RES_GPIO_Port,oled_RES_Pin, GPIO_PIN_SET)
    #define oled_DC_Clr()   HAL_GPIO_WritePin(oled_DC_GPIO_Port,oled_DC_Pin, GPIO_PIN_RESET)
    #define oled_DC_Set()   HAL_GPIO_WritePin(oled_DC_GPIO_Port,oled_DC_Pin, GPIO_PIN_SET)

    
#else
    void oled_I2C_Delay(void);
    void oled_I2C_Start(void);
    void oled_I2C_Stop(void);
    void oled_I2C_WaitAck(void);
    void oled_I2C_Send_Byte(uint8_t dat);
    #define oled_SCL_Pin GPIO_PIN_13  //###修改GPIO
    #define oled_SCL_GPIO_Port GPIOC
    #define oled_SDA_Pin GPIO_PIN_14
    #define oled_SDA_GPIO_Port GPIOC

    #define oled_SCL_Clr() HAL_GPIO_WritePin(oled_SCL_GPIO_Port,oled_SCL_Pin, GPIO_PIN_RESET)
    #define oled_SCL_Set() HAL_GPIO_WritePin(oled_SCL_GPIO_Port,oled_SCL_Pin, GPIO_PIN_SET)
    #define oled_SDA_Clr() HAL_GPIO_WritePin(oled_SDA_GPIO_Port,oled_SDA_Pin, GPIO_PIN_RESET)
    #define oled_SDA_Set() HAL_GPIO_WritePin(oled_SDA_GPIO_Port,oled_SDA_Pin, GPIO_PIN_SET)

#endif



//-----------------oled操作定义----------------
#define oled_CMD  0	//写命令
#define oled_DATA 1 //写数据

/*-------------------------------------------
 * oled 基础控制函数
 *-----------------------------------------*/
void oled_Init(void);
void oled_refresh(void);
void oled_write_byte(uint8_t dat, uint8_t mode); // 向oled写入一个字节数据mode: 0-命令 1-数据

void oled_colorTurn(uint8_t i); // 颜色反转控制 (0:正常显示 1:反色显示)
void oled_displayTurn(uint8_t i);// 屏幕显示方向控制 (0:正常方向 1:旋转180度)
void oled_display_On(void);
void oled_display_Off(void);
void oled_clear(void);


/*-------------------------------------------
 * 图形绘制函数
 *-----------------------------------------*/
void oled_drawPoint(uint8_t x, uint8_t y,  uint8_t mode);
void oled_drawLine(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint8_t mode);
void oled_drawCircle(uint8_t x, uint8_t y, uint8_t r);

/*-------------------------------------------
 * 字符和文本显示函数
 *-----------------------------------------*/
void oled_showChar(uint8_t x, uint8_t y, uint8_t chr, uint8_t size1, uint8_t mode);
void oled_showString(uint8_t x, uint8_t y, const uint8_t *p, uint8_t size, uint8_t mode);
void oled_showNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size1,uint8_t mode);
void oled_showFloat(uint8_t x, uint8_t y, float num, uint8_t len, uint8_t decimals, uint8_t size1, uint8_t mode);
void oled_showCharWithDot(uint8_t x, uint8_t y, uint8_t chr, uint8_t size1, uint8_t mode);
void oled_showBinWithPrefix(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size1, uint8_t mode);
void oled_showHexWithPrefix(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size1, uint8_t mode);
void oled_showHex(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size1, uint8_t mode);
void oled_showBin(uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size1, uint8_t mode);
void oled_showChinese(uint8_t x,uint8_t y,uint8_t num);
void oled_Scrolldisplay(uint8_t num,uint8_t space);
void oled_show_name_rolling_adapted(void);
/*-------------------------------------------
 * 调试和测试函数
 *-----------------------------------------*/
void oled_debug_interrupt(const uint8_t *p, float x); // 调试中断信息显示
void oled_showPicture(uint8_t x, uint8_t y, uint8_t sizex, uint8_t sizey, uint8_t BMP[], uint8_t mode);
void oled_Test(void);//填充测试
void fps(void);

extern uint8_t oled_gram[144][8];
#endif

